package com.sophialex.health.record.ui.baseinfo;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.part.ViewPart;

import com.sophialex.health.common.platform.pojo.Geography;
import com.sophialex.health.person.vo.HrFamily;
import com.sophialex.health.person.vo.HrPerson;
import com.sophialex.health.record.Messages;
import com.sophialex.health.record.common.Constants;
import com.sophialex.health.record.common.GeographyTreeCombo;
import com.sophialex.health.record.common.GeographyTreeInit;
import com.sophialex.health.record.common.bind.CheckboxBindingUtil;
import com.sophialex.health.record.common.bind.swt.annotations.AnnotionProcessor;
import com.sophialex.health.record.common.bind.swt.annotations.BindTo;
import com.sophialex.health.record.common.bind.swt.annotations.ComboDataBindTo;
import com.sophialex.health.record.common.util.DataSource;
import com.sophialex.health.record.common.util.HealthRecordContants;
import com.sophialex.health.record.common.util.ListenerUtil;
import com.sophialex.health.record.common.util.TextCascade;
import com.sophialex.health.record.common.utils.CommonUtils;
import com.sophialex.health.record.common.utils.ImageUtil;
import com.sophialex.health.record.dialog.HrPersonMemberSelectDlg;
import com.sophialex.health.record.dialog.QuackAddPersonDialog;
import com.sophialex.health.record.lktable.KtableColumnDesc;
import com.sophialex.health.system.frame.dialog.DialogManager;
import com.sophialex.health.system.frame.util.Assert;
import com.sophialex.health.system.lktable.LKTable;
import com.sophialex.health.system.validation.ValidateType.ValidateEnum;
import com.sophialex.health.system.validation.validator.CommonFieldValidate;
import com.sophialex.health.system.validation.validator.SophiaValidateUtil;

/**
 * 家庭基本信息UI
 * <p>
 * Title:Health
 * </p>
 * <p>
 * PersonBaseInfoUI
 * </p>
 * Alex Apr 25, 2011 1:59:00 PM create
 * 
 * @author <a href='wanghao924@126.com'>Alex</a> QQ: 873987060;
 * @version 1.0
 */
public abstract class FamilyUI extends ViewPart {
	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());

	public FamilyUI() {
	}

	public static final String ID = "com.sophialex.health.record.ui.baseinfo.FamilyUI";

	public Composite composite;

	public Composite composite_1;

	public Composite composite_2;

	public Composite composite_3;

	public Composite composite_4;

	private CheckboxBindingUtil boxBindingUtil = new CheckboxBindingUtil();

	protected HrFamily hrFamily = new HrFamily();

	protected Hyperlink chooseHuZuLink;

	protected Hyperlink generNolink;

	@BindTo(beanPath = "hrFamily.familyMasterName")
	protected Text txt_hzxm; // 户主姓名

	private GeographyTreeCombo combo_jwh; // 村委会/居委会

	@BindTo(beanPath = "hrFamily.archiveSerial")
	protected Text text_dabh; // 家庭档案编号

	@BindTo(beanPath = "hrFamily.cadress")
	protected Text txt_jtdz; // 家庭住址

	@BindTo(beanPath = "hrFamily.phone")
	protected Text txt_phone;// 家庭电话

	@BindTo(beanPath = "hrFamily.totalArea")
	protected Text txt_jzzmj; // 居住总面积

	@BindTo(beanPath = "hrFamily.averageArea")
	protected Text txt_rjjzmj;// 人均居住面积

	@ComboDataBindTo(dataPath = "codeNum", beanPath = "hrFamily.houseType")
	protected Combo combo_fwlx; // 房屋类型

	@BindTo(beanPath = "hrFamily.houseTypeOther")
	protected Text txt_fwlx; // 房屋类型其他

	@ComboDataBindTo(dataPath = "codeNum", beanPath = "hrFamily.cfUsetype")
	protected Combo combo_cfsyfs; // 厨房使用方式

	@ComboDataBindTo(dataPath = "codeNum", beanPath = "hrFamily.cfPaifeng")
	protected Combo combo_cfpffs; // 厨房排风方式

	@BindTo(beanPath = "hrFamily.drinkWaterOther")
	protected Text txt_ys; // 饮水其他

	@BindTo(beanPath = "hrFamily.fuelTypeOther")
	protected Text txt_rlqt;// 燃料其他

	@ComboDataBindTo(dataPath = "codeNum", beanPath = "hrFamily.scl")
	protected Combo combo_scl; // 禽畜栏

	@ComboDataBindTo(dataPath = "codeNum", beanPath = "hrFamily.wsWc")
	protected Combo combo_wscs; // 卫生厕所

	@ComboDataBindTo(dataPath = "codeNum", beanPath = "hrFamily.noWsWc")
	protected Combo combo_fwscs; // 非卫生厕所

	@ComboDataBindTo(dataPath = "codeNum", beanPath = "hrFamily.ljcl")
	protected Combo combo_ljcl; // 垃圾处理

	@BindTo(beanPath = "hrFamily.ljclOther")
	protected Text txt_ljclqt; // 垃圾处理其他

	protected ToolItem toolItemEdit;

	protected ToolItem toolItemDel;

	protected ToolItem toolItemSave;

	protected ToolItem toolItemCancel;

	protected ToolItem toolItemAdd;

	protected ToolItem toolFamilyItemAdd;

	protected ToolItem toolFamilyItemEdit;

	protected ToolItem toolFamilyItemDel;

	public LKTable familyMemberTable;

	public List<HrPerson> hrPersonList;

	public List<HrPerson> hrPersonSelectList;

	public List<KtableColumnDesc> desclist;

	protected GeographyTreeInit treeObj = new GeographyTreeInit();

	protected Control[] tabList;

	protected FamilyInfoViewState viewstate = FamilyInfoViewState.SHOW_VIEW;

	protected AnnotionProcessor annotionProcessor = new AnnotionProcessor(this);

	protected SophiaValidateUtil validateUtil = new SophiaValidateUtil();

	protected HrPerson hrPerson;

	private static final int ADD_HUZHU = 1; // 增加户主

	protected enum FamilyInfoViewState {
		ADD_VIEW, EDIT_VIEW, SHOW_VIEW;
	}

	/**
	 * Create contents of the view part.
	 * 
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		// hrFamily = BeanFactory.proxyBean(new HrFamily(), HrFamily.class);
		Composite container = new Composite(parent, SWT.NONE);
		container.setLayout(new FormLayout());
		{
			composite_1 = new Composite(container, SWT.NONE);
			composite_1.setLayout(new FillLayout(SWT.HORIZONTAL));
			{
				FormData formData = new FormData();
				formData.height = 50;
				formData.right = new FormAttachment(100);
				formData.top = new FormAttachment(0);
				formData.left = new FormAttachment(0);
				composite_1.setLayoutData(formData);
			}
			{
				ToolBar toolBar = new ToolBar(composite_1, SWT.FLAT | SWT.NONE);
				toolBar.setBackgroundImage(ImageUtil.TBBJ);
				{
					toolItemAdd = new ToolItem(toolBar, SWT.NONE);
					toolItemAdd.setText(Messages.getString("RecordUI.0")); //$NON-NLS-1$
					toolItemAdd.setImage(ImageUtil.add);
					toolItemAdd.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doAdd();
						}
					});
				}
				{
					toolItemEdit = new ToolItem(toolBar, SWT.NONE);
					toolItemEdit.setText(Messages.getString("RecordUI.1")); //$NON-NLS-1$
					toolItemEdit.setImage(ImageUtil.edit);
					toolItemEdit.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doEdit();
						}
					});
				}
				{
					toolItemDel = new ToolItem(toolBar, SWT.NONE);
					toolItemDel.setText(Messages.getString("RecordUI.2"));
					toolItemDel.setImage(ImageUtil.delete);
					toolItemDel.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doDel();
						}
					});
				}
				{
					ToolItem toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
				}
				{
					toolItemSave = new ToolItem(toolBar, SWT.NONE);
					toolItemSave.setText(Messages.getString("RecordUI.3"));
					toolItemSave.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doSave();
						}
					});
					toolItemSave.setImage(ImageUtil.save);
				}

				{
					toolItemCancel = new ToolItem(toolBar, SWT.NONE);
					toolItemCancel.setText(Messages.getString("RecordUI.4"));
					toolItemCancel.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doCancel();
						}
					});
					toolItemCancel.setImage(ImageUtil.cancel);
				}

				{
					ToolItem toolItem = new ToolItem(toolBar, SWT.NONE);
					toolItem.setText(Messages.getString("RecordUI.5"));
					toolItem.setImage(ImageUtil.print);
					toolItem.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doPrint();
						}
					});
				}
				{
					ToolItem toolItem = new ToolItem(toolBar, SWT.NONE);
					toolItem.setText(Messages.getString("RecordUI.6"));
					toolItem.setImage(ImageUtil.exit);
					toolItem.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doExit();
						}
					});
				}
			}
		}

		{
			Composite composite = new Composite(container, SWT.NONE);
			{
				FormData formData = new FormData();
				formData.top = new FormAttachment(composite_1, 0);
				formData.bottom = new FormAttachment(100, -4);
				formData.right = new FormAttachment(composite_1, 0, SWT.RIGHT);
				formData.left = new FormAttachment(composite_1, 0, SWT.LEFT);
				composite.setLayout(new FillLayout(SWT.FILL));
				composite.setLayoutData(formData);
			}
			{
				final SashForm sashForm = new SashForm(composite, SWT.VERTICAL);
				sashForm.setSashWidth(5);
				composite_1 = new Composite(sashForm, SWT.NONE);
				composite_1.setLayout(new FillLayout());

				createFamilyUIControl(composite_1);

				composite_2 = new Composite(sashForm, SWT.NONE);
				composite_2.setLayout(new FormLayout());

				{
					composite_3 = new Composite(composite_2, SWT.NONE);
					composite_3.setLayout(new FillLayout(SWT.HORIZONTAL));
					{
						FormData formData = new FormData();
						formData.height = 25;
						formData.right = new FormAttachment(100);
						formData.top = new FormAttachment(0);
						formData.left = new FormAttachment(0);
						composite_3.setLayoutData(formData);
					}
				}
				{
					ToolBar toolBar = new ToolBar(composite_3, SWT.FLAT | SWT.NONE);
					toolBar.setBackgroundImage(ImageUtil.TBBJ);
					{
						toolFamilyItemAdd = new ToolItem(toolBar, SWT.NONE);
						toolFamilyItemAdd.setToolTipText(Messages.getString("RecordUI.0"));
						toolFamilyItemAdd.setImage(ImageUtil.add_item);
						toolFamilyItemAdd.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								doAddItem();
							}
						});
					}
					{
						toolFamilyItemEdit = new ToolItem(toolBar, SWT.NONE);
						toolFamilyItemEdit.setToolTipText(Messages.getString("RecordUI.3"));
						toolFamilyItemEdit.setImage(ImageUtil.save_item);
						toolFamilyItemEdit.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								doSaveItem();
							}
						});
					}
					{
						toolFamilyItemDel = new ToolItem(toolBar, SWT.NONE);
						toolFamilyItemDel.setToolTipText(Messages.getString("RecordUI.2"));
						toolFamilyItemDel.setImage(ImageUtil.delete_item);
						toolFamilyItemDel.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								doDelItem();
							}
						});
					}

				}
				composite_4 = new Composite(composite_2, SWT.NONE);
				{
					FormData formData = new FormData();
					formData.top = new FormAttachment(composite_3, 0);
					formData.bottom = new FormAttachment(100, -4);
					formData.right = new FormAttachment(composite_3, 0, SWT.RIGHT);
					formData.left = new FormAttachment(composite_3, 0, SWT.LEFT);
					composite_4.setLayout(new FillLayout(SWT.FILL));
					composite_4.setLayoutData(formData);
				}

				sashForm.setWeights(new int[] { 5, 2 });

			}

		}

		createActions();

		initCombo();
		addListener();
		initializeToolBar();
		initializeMenu();
		AnnotionProcessor ap = new AnnotionProcessor(this);
		ap.process();
		initUI();
		this.setPartName(Messages.getString("FamilyUI.Title0"));

	}

	protected void initUI() {
		txt_hzxm.setFocus();
		TextCascade.cascade(getCombo_fwlx(), getTxt_fwlx(), "codeNum", 9, true);
		TextCascade.cascade(getCombo_ljcl(), getTxt_ljclqt(), "codeNum", 9, true);
	}

	protected void addListener() {

		chooseHuZuLink.addHyperlinkListener(new HyperlinkAdapter() {
			public void linkActivated(HyperlinkEvent e) {
				chooseHuZhu();
			}
		});

		generNolink.addHyperlinkListener(new HyperlinkAdapter() {
			public void linkActivated(HyperlinkEvent e) {
				Geography geography = (Geography) combo_jwh.getTreeItemData();
				if(geography != null && !geography.getfTreebh().equals("0")) {
					Long serialNo = DataSource.hrPersonService.getFamilySerialNo(Long.valueOf(geography.getfTreebh()));
					if(serialNo != null) {
						text_dabh.setText(serialNo.toString());
					}

				} else {
					DialogManager.invokeWarnDlg(Messages.getString("FamilyUI_ERROR.4"));
				}

			}
		});
	}

	protected void chooseHuZhu() {
		hrPerson = new HrPerson();
		try {
			HrPerson query = new HrPerson();
			if(viewstate == FamilyInfoViewState.SHOW_VIEW) {
				query.setName(null);
				hrPersonSelectList = DataSource.hrPersonService.getHrPersonFamilyList(query);
				if(com.sophia.util.CommonUtils.isEmpty(hrPersonSelectList)) {
					DialogManager.invokeWarnDlg(Messages.getString("FamilyUI_INFO.7"));
					return;
				}
			} else {
				// if(StringUtils.isBlank(txt_hzxm.getText())){
				// DialogManager.invokeWarnDlg(Messages.getString("FamilyUI_ERROR.0"));
				// return ;
				// }
				query.setName(txt_hzxm.getText());
				hrPersonSelectList = DataSource.hrPersonService.findHrPersonHuZhu(query);
			}

			if(hrPersonSelectList != null && hrPersonSelectList.size() > 0) {
				HrPerson selectPerson;
				if(viewstate == FamilyInfoViewState.SHOW_VIEW) {
					HrPersonMemberSelectDlg dlg = new HrPersonMemberSelectDlg(familyMemberTable, getViewSite().getShell(), hrPersonSelectList, hrPerson,
							HealthRecordContants.NOSHOW_ADD_PERSON_DIALOG_TYPE);
					selectPerson = (HrPerson) dlg.open();
				} else {
					HrPersonMemberSelectDlg dlg = new HrPersonMemberSelectDlg(familyMemberTable, getViewSite().getShell(), hrPersonSelectList, hrPerson);
					selectPerson = (HrPerson) dlg.open();
				}

				if(selectPerson != null) {
					if(viewstate == FamilyInfoViewState.SHOW_VIEW) {
						if(selectPerson.getPerFamilyId() != null) {
							HrFamily tempFamily = DataSource.hrFamilyService.getHrFamily(selectPerson.getPerFamilyId());
							annotionProcessor.updateUI(hrFamily, tempFamily);
							if(tempFamily.getHamlet() != null) {
								CommonUtils.selectGeography(getCombo_jwh(), tempFamily.getHamlet());
							}
						}
					}
					txt_hzxm.setText(selectPerson.getName());
					CommonUtils.selectGeography(getCombo_jwh(), selectPerson.getHamlet());
					if(viewstate == FamilyInfoViewState.ADD_VIEW) {
						doAddHuZhuToTable(selectPerson);
					} else {
						removeAllMember();
						hrPersonList = DataSource.hrPersonService.findFamilyPerson(selectPerson.getPerFamilyId() == null ? 1l : selectPerson.getPerFamilyId());
						familyMemberTable.setInput(hrPersonList);
					}
					hrFamily.setFamilyMasterId(selectPerson.getId());
					BeanUtils.copyProperties(hrPerson, selectPerson);
				}
			} else {
				if(DialogManager.invokeConfirmDlg(query.getName() + Messages.getString("HrPersonAddInfo.4"))) {
					query.setPerRelaMaster(Constants.HZ);
					QuackAddPersonDialog addPersonDialog = new QuackAddPersonDialog(familyMemberTable, query, getSite().getShell(), SWT.NONE, ADD_HUZHU);

					HrPerson t = (HrPerson) addPersonDialog.open();
					if(t != null) {
						BeanUtils.copyProperties(hrPerson, t);
						hrPersonList = new ArrayList<HrPerson>();
						hrPersonList.add(hrPerson);
						familyMemberTable.setInput(hrPersonList);
						familyMemberTable.redraw();
						if(t.getHamlet() != null) {
							CommonUtils.selectGeography(getCombo_jwh(), t.getHamlet());
						}

					}
				}
			}
		}
		catch(Exception e) {
			DialogManager.invokeWarnDlg(e.getLocalizedMessage());
		}
	}

	protected void getPerson(int col) {
		HrPerson hrPerson = (HrPerson) familyMemberTable.getSelection();
		try {
			HrPerson query = new HrPerson();
			query.setName(hrPerson.getName());
			hrPersonList = DataSource.hrPersonService.findPageInfoHrPerson(query, null);

			if(hrPersonList != null && hrPersonList.size() > 0) {
				HrPerson selectPerson;
				if(hrPersonList.size() == 1) {
					selectPerson = hrPersonList.get(0);
				} else {
					HrPersonMemberSelectDlg dlg = new HrPersonMemberSelectDlg(familyMemberTable, getViewSite().getShell(), hrPersonList, hrPerson);
					selectPerson = (HrPerson) dlg.open();
				}

				if(selectPerson != null) {
					BeanUtils.copyProperties(hrPerson, selectPerson);
					familyMemberTable.redraw();
				}
			} else {
				if(DialogManager.invokeConfirmDlg(hrPerson.getName() + Messages.getString("HrPersonAddInfo.0"))) {
					QuackAddPersonDialog addPersonDialog = new QuackAddPersonDialog(familyMemberTable, hrPerson, getSite().getShell(), SWT.NONE);
					HrPerson t = (HrPerson) addPersonDialog.open();
					if(t != null) {
						BeanUtils.copyProperties(hrPerson, t);
						familyMemberTable.redraw();
					}
				} else {
					familyMemberTable.editElement(hrPerson, "name");
				}
			}
		}
		catch(Exception e) {
			DialogManager.invokeWarnDlg(e.getLocalizedMessage());
		}

	}

	private void createFamilyUIControl(Composite parent) {
		Composite container = toolkit.createComposite(parent, SWT.NONE);
		toolkit.paintBordersFor(container);
		container.setLayout(new FillLayout(SWT.HORIZONTAL));
		{
			ScrolledForm scrldfrmNewScrolledform = toolkit.createScrolledForm(container);
			toolkit.paintBordersFor(scrldfrmNewScrolledform);
			scrldfrmNewScrolledform.getBody().setLayout(new FormLayout());

			Section sctnNewSection = toolkit.createSection(scrldfrmNewScrolledform.getBody(), Section.DESCRIPTION | Section.TITLE_BAR); // Section.TWISTIE
			// 是带收缩的
			FormData fd_sctnNewSection = new FormData();
			fd_sctnNewSection.bottom = new FormAttachment(0, 130);
			fd_sctnNewSection.right = new FormAttachment(100, -10);
			fd_sctnNewSection.top = new FormAttachment(0, 10);
			fd_sctnNewSection.left = new FormAttachment(0, 10);
			sctnNewSection.setLayoutData(fd_sctnNewSection);
			toolkit.paintBordersFor(sctnNewSection);
			sctnNewSection.setText("家庭基本信息");

			Composite composite = toolkit.createComposite(sctnNewSection, SWT.NONE);
			toolkit.paintBordersFor(composite);
			sctnNewSection.setClient(composite);
			composite.setLayout(new FormLayout());

			Label label_hzxm = toolkit.createLabel(composite, "户主姓名：", SWT.NONE);

			FormData fd_label_hzxm = new FormData();
			fd_label_hzxm.top = new FormAttachment(0, 10);
			fd_label_hzxm.left = new FormAttachment(5, 0);
			label_hzxm.setLayoutData(fd_label_hzxm);

			txt_hzxm = toolkit.createText(composite, "", SWT.NONE);
			FormData fd_txt_hzxm = new FormData();
			fd_txt_hzxm.right = new FormAttachment(label_hzxm, 242, SWT.RIGHT);
			fd_txt_hzxm.top = new FormAttachment(label_hzxm, -10, SWT.TOP);
			fd_txt_hzxm.bottom = new FormAttachment(label_hzxm, 0, SWT.BOTTOM);
			fd_txt_hzxm.left = new FormAttachment(label_hzxm, 6);
			txt_hzxm.setLayoutData(fd_txt_hzxm);

			{
				Integer[] type = { ValidateEnum.EMPTY.getType() };
				validateUtil.createTextValidateField(txt_hzxm, new CommonFieldValidate(type, Messages.getString("ValidateUI.0")));
			}

			chooseHuZuLink = toolkit.createHyperlink(composite, "选择户主", SWT.NONE);
			FormData fd_hprlnkNewHyperlink = new FormData();
			fd_hprlnkNewHyperlink.right = new FormAttachment(txt_hzxm, 65, SWT.RIGHT);
			fd_hprlnkNewHyperlink.bottom = new FormAttachment(txt_hzxm, 0, SWT.BOTTOM);
			fd_hprlnkNewHyperlink.left = new FormAttachment(txt_hzxm, 15);
			chooseHuZuLink.setLayoutData(fd_hprlnkNewHyperlink);
			toolkit.paintBordersFor(chooseHuZuLink);

			Label label_1 = toolkit.createLabel(composite, "村/居委会：", SWT.NONE);
			FormData fd_label_1 = new FormData();
			fd_label_1.left = new FormAttachment(chooseHuZuLink, 50);
			fd_label_1.bottom = new FormAttachment(chooseHuZuLink, 0, SWT.BOTTOM);
			label_1.setLayoutData(fd_label_1);

			combo_jwh = new GeographyTreeCombo(composite, treeObj, SWT.READ_ONLY | SWT.SIMPLE);
			FormData fd_combo = new FormData();
			fd_combo.bottom = new FormAttachment(label_hzxm, 0, SWT.BOTTOM);
			fd_combo.right = new FormAttachment(label_1, 242, SWT.RIGHT);
			fd_combo.top = new FormAttachment(txt_hzxm, 0, SWT.TOP);
			fd_combo.left = new FormAttachment(label_1, 6);
			combo_jwh.setLayoutData(fd_combo);
			toolkit.adapt(combo_jwh);
			toolkit.paintBordersFor(combo_jwh);

			Label label_2 = toolkit.createLabel(composite, "家庭档案编号：", SWT.NONE);
			FormData fd_label_2 = new FormData();
			fd_label_2.left = new FormAttachment(combo_jwh, 40);
			fd_label_2.bottom = new FormAttachment(label_hzxm, 0, SWT.BOTTOM);
			label_2.setLayoutData(fd_label_2);

			text_dabh = toolkit.createText(composite, "", SWT.NONE);
			FormData fd_text_dabh = new FormData();
			fd_text_dabh.right = new FormAttachment(label_2, 242, SWT.RIGHT);
			fd_text_dabh.top = new FormAttachment(label_2, -10, SWT.TOP);
			fd_text_dabh.bottom = new FormAttachment(label_2, 0, SWT.BOTTOM);
			fd_text_dabh.left = new FormAttachment(label_2, 6);
			text_dabh.setLayoutData(fd_text_dabh);

			{
				Integer[] type = { ValidateEnum.EMPTY.getType() };
				validateUtil.createTextValidateField(text_dabh, new CommonFieldValidate(type, Messages.getString("ValidateUI.1")));
			}

			generNolink = toolkit.createHyperlink(composite, "生成编号", SWT.NONE);
			FormData fdgenerNolink = new FormData();
			fdgenerNolink.right = new FormAttachment(text_dabh, 65, SWT.RIGHT);
			fdgenerNolink.bottom = new FormAttachment(text_dabh, 0, SWT.BOTTOM);
			fdgenerNolink.left = new FormAttachment(text_dabh, 15);
			generNolink.setLayoutData(fdgenerNolink);
			toolkit.paintBordersFor(generNolink);

			Label label_3 = toolkit.createLabel(composite, "家庭住址：", SWT.NONE);
			FormData fd_label_3 = new FormData();
			fd_label_3.bottom = new FormAttachment(100, -10);
			fd_label_3.right = new FormAttachment(label_hzxm, 0, SWT.RIGHT);
			label_3.setLayoutData(fd_label_3);

			txt_jtdz = toolkit.createText(composite, "", SWT.NONE);
			FormData fd_txtNewText_2 = new FormData();
			fd_txtNewText_2.top = new FormAttachment(label_3, -10, SWT.TOP);
			fd_txtNewText_2.bottom = new FormAttachment(label_3, 0, SWT.BOTTOM);
			fd_txtNewText_2.right = new FormAttachment(label_3, 242, SWT.RIGHT);
			fd_txtNewText_2.left = new FormAttachment(label_3, 6);
			txt_jtdz.setLayoutData(fd_txtNewText_2);

			Label label_4 = toolkit.createLabel(composite, "家庭电话：", SWT.NONE);
			FormData fd_label_4 = new FormData();
			fd_label_4.bottom = new FormAttachment(label_3, 0, SWT.BOTTOM);
			fd_label_4.right = new FormAttachment(label_1, 0, SWT.RIGHT);
			label_4.setLayoutData(fd_label_4);

			txt_phone = toolkit.createText(composite, "", SWT.NONE);
			FormData fd_txtNewText_3 = new FormData();
			fd_txtNewText_3.right = new FormAttachment(combo_jwh, 0, SWT.RIGHT);
			fd_txtNewText_3.left = new FormAttachment(label_4, 6);
			fd_txtNewText_3.bottom = new FormAttachment(label_4, 0, SWT.BOTTOM);
			fd_txtNewText_3.top = new FormAttachment(txt_jtdz, 0, SWT.TOP);
			txt_phone.setLayoutData(fd_txtNewText_3);

			Section sctnNewSection_1 = toolkit.createSection(scrldfrmNewScrolledform.getBody(), Section.DESCRIPTION | Section.TITLE_BAR);
			FormData fd_sctnNewSection_1 = new FormData();
			fd_sctnNewSection_1.bottom = new FormAttachment(sctnNewSection, 440, SWT.BOTTOM);
			fd_sctnNewSection_1.top = new FormAttachment(sctnNewSection, 30);
			fd_sctnNewSection_1.left = new FormAttachment(0, 10);
			fd_sctnNewSection_1.right = new FormAttachment(sctnNewSection, 0, SWT.RIGHT);
			sctnNewSection_1.setLayoutData(fd_sctnNewSection_1);
			toolkit.paintBordersFor(sctnNewSection_1);
			sctnNewSection_1.setText("家庭社会经济状况");

			Composite composite_1 = toolkit.createComposite(sctnNewSection_1, SWT.NONE);
			toolkit.paintBordersFor(composite_1);
			sctnNewSection_1.setClient(composite_1);
			composite_1.setLayout(new FormLayout());

			Label label_5 = toolkit.createLabel(composite_1, "  户属性：", SWT.NONE);
			FormData fd_label_5 = new FormData();
			fd_label_5.top = new FormAttachment(0, 10);
			fd_label_5.left = new FormAttachment(5, 0);
			label_5.setLayoutData(fd_label_5);

			Button[] hsxButtons = CommonUtils.initCheckBoxUI(toolkit, composite_1, label_5, "HSX", new int[] { 15 }, hrFamily, "familylType");

			Label lblNewLabel = toolkit.createLabel(composite_1, "居住面积：", SWT.NONE);
			FormData fd_lblNewLabel = new FormData();
			fd_lblNewLabel.top = new FormAttachment(label_5, 30);
			fd_lblNewLabel.right = new FormAttachment(label_5, 0, SWT.RIGHT);
			lblNewLabel.setLayoutData(fd_lblNewLabel);

			Label lblNewLabel_1 = toolkit.createLabel(composite_1, "居住总面积", SWT.NONE);
			FormData fd_lblNewLabel_1 = new FormData();
			fd_lblNewLabel_1.bottom = new FormAttachment(lblNewLabel, 0, SWT.BOTTOM);
			fd_lblNewLabel_1.left = new FormAttachment(hsxButtons[0], 0, SWT.LEFT);
			lblNewLabel_1.setLayoutData(fd_lblNewLabel_1);

			txt_jzzmj = toolkit.createText(composite_1, "", SWT.NONE);
			FormData fd_txt_jzzmj = new FormData();
			fd_txt_jzzmj.right = new FormAttachment(lblNewLabel_1, 120, SWT.RIGHT);
			fd_txt_jzzmj.bottom = new FormAttachment(lblNewLabel_1, 0, SWT.BOTTOM);
			fd_txt_jzzmj.top = new FormAttachment(lblNewLabel_1, -10, SWT.TOP);
			fd_txt_jzzmj.left = new FormAttachment(lblNewLabel_1, 10);
			txt_jzzmj.setLayoutData(fd_txt_jzzmj);

			Label label_6 = toolkit.createLabel(composite_1, "平方米", SWT.NONE);
			FormData fd_label_6 = new FormData();
			fd_label_6.bottom = new FormAttachment(lblNewLabel, 0, SWT.BOTTOM);
			fd_label_6.left = new FormAttachment(txt_jzzmj, 6);
			label_6.setLayoutData(fd_label_6);

			Label lblNewLabel_2 = toolkit.createLabel(composite_1, "人均居住面积", SWT.NONE);
			FormData fd_lblNewLabel_2 = new FormData();
			fd_lblNewLabel_2.bottom = new FormAttachment(lblNewLabel, 0, SWT.BOTTOM);
			fd_lblNewLabel_2.left = new FormAttachment(label_6, 113);
			lblNewLabel_2.setLayoutData(fd_lblNewLabel_2);

			txt_rjjzmj = toolkit.createText(composite_1, "", SWT.NONE);
			FormData fd_txt_rjjzmj = new FormData();
			fd_txt_rjjzmj.right = new FormAttachment(lblNewLabel_2, 120, SWT.RIGHT);
			fd_txt_rjjzmj.bottom = new FormAttachment(lblNewLabel_2, 0, SWT.BOTTOM);
			fd_txt_rjjzmj.top = new FormAttachment(lblNewLabel_2, -10, SWT.TOP);
			fd_txt_rjjzmj.left = new FormAttachment(lblNewLabel_2, 10);
			txt_rjjzmj.setLayoutData(fd_txt_rjjzmj);

			Label label_7 = toolkit.createLabel(composite_1, "平方米", SWT.NONE);
			FormData fd_label_7 = new FormData();
			fd_label_7.bottom = new FormAttachment(lblNewLabel, 0, SWT.BOTTOM);
			fd_label_7.left = new FormAttachment(txt_rjjzmj, 6);
			label_7.setLayoutData(fd_label_7);

			Label lblNewLabel_3 = toolkit.createLabel(composite_1, "房屋类型：", SWT.NONE);
			FormData fd_lblNewLabel_3 = new FormData();
			fd_lblNewLabel_3.top = new FormAttachment(lblNewLabel, 30);
			fd_lblNewLabel_3.right = new FormAttachment(label_5, 0, SWT.RIGHT);
			lblNewLabel_3.setLayoutData(fd_lblNewLabel_3);

			combo_fwlx = new Combo(composite_1, SWT.NONE);
			FormData fd_combo_1 = new FormData();
			fd_combo_1.bottom = new FormAttachment(lblNewLabel_3, 2, SWT.BOTTOM);
			fd_combo_1.right = new FormAttachment(lblNewLabel_3, 136, SWT.RIGHT);
			fd_combo_1.top = new FormAttachment(lblNewLabel_3, -10, SWT.TOP);
			fd_combo_1.left = new FormAttachment(lblNewLabel_3, 6);
			combo_fwlx.setLayoutData(fd_combo_1);
			toolkit.adapt(combo_fwlx);
			toolkit.paintBordersFor(combo_fwlx);

			txt_fwlx = toolkit.createText(composite_1, "", SWT.NONE);
			FormData fd_txt_fwlx = new FormData();
			fd_txt_fwlx.right = new FormAttachment(combo_fwlx, 120, SWT.RIGHT);
			fd_txt_fwlx.left = new FormAttachment(combo_fwlx, 13);
			fd_txt_fwlx.top = new FormAttachment(lblNewLabel_3, -10, SWT.TOP);
			fd_txt_fwlx.bottom = new FormAttachment(lblNewLabel_3, 0, SWT.BOTTOM);
			txt_fwlx.setLayoutData(fd_txt_fwlx);

			Label lblNewLabel_4 = toolkit.createLabel(composite_1, "厨房使用方式：", SWT.NONE);
			FormData fd_lblNewLabel_4 = new FormData();
			fd_lblNewLabel_4.bottom = new FormAttachment(lblNewLabel_3, 0, SWT.BOTTOM);
			fd_lblNewLabel_4.right = new FormAttachment(lblNewLabel_2, 0, SWT.RIGHT);
			lblNewLabel_4.setLayoutData(fd_lblNewLabel_4);

			combo_cfsyfs = new Combo(composite_1, SWT.NONE);
			FormData fd_combo_2 = new FormData();
			fd_combo_2.bottom = new FormAttachment(lblNewLabel_4, 0, SWT.BOTTOM);
			fd_combo_2.right = new FormAttachment(lblNewLabel_4, 136, SWT.RIGHT);
			fd_combo_2.top = new FormAttachment(lblNewLabel_4, -10, SWT.TOP);
			fd_combo_2.left = new FormAttachment(lblNewLabel_4, 10);
			combo_cfsyfs.setLayoutData(fd_combo_2);
			toolkit.adapt(combo_cfsyfs);
			toolkit.paintBordersFor(combo_cfsyfs);

			Label lblNewLabel_5 = toolkit.createLabel(composite_1, "厨房排风设施：", SWT.NONE);
			FormData fd_lblNewLabel_5 = new FormData();
			fd_lblNewLabel_5.bottom = new FormAttachment(lblNewLabel_4, 0, SWT.BOTTOM);
			fd_lblNewLabel_5.left = new FormAttachment(combo_cfsyfs, 113);
			lblNewLabel_5.setLayoutData(fd_lblNewLabel_5);

			combo_cfpffs = new Combo(composite_1, SWT.NONE);
			FormData fd_combo_3 = new FormData();
			fd_combo_3.bottom = new FormAttachment(lblNewLabel_5, 0, SWT.BOTTOM);
			fd_combo_3.right = new FormAttachment(lblNewLabel_5, 136, SWT.RIGHT);
			fd_combo_3.top = new FormAttachment(lblNewLabel_5, -10, SWT.TOP);
			fd_combo_3.left = new FormAttachment(lblNewLabel_5, 10);
			combo_cfpffs.setLayoutData(fd_combo_3);
			toolkit.adapt(combo_cfpffs);
			toolkit.paintBordersFor(combo_cfpffs);

			Label lblNewLabel_6 = toolkit.createLabel(composite_1, "饮水：", SWT.NONE);
			FormData fd_lblNewLabel_6 = new FormData();
			fd_lblNewLabel_6.top = new FormAttachment(lblNewLabel_3, 30);
			fd_lblNewLabel_6.right = new FormAttachment(label_5, 0, SWT.RIGHT);
			lblNewLabel_6.setLayoutData(fd_lblNewLabel_6);

			Button[] ysButtons = CommonUtils.initCheckBoxUI(toolkit, composite_1, lblNewLabel_6, "YS", new int[] { 15 }, hrFamily, "drinkWater");

			txt_ys = toolkit.createText(composite_1, "", SWT.NONE);
			FormData fd_txt_ys = new FormData();
			fd_txt_ys.right = new FormAttachment(ysButtons[ysButtons.length - 1], 120, SWT.RIGHT);
			fd_txt_ys.left = new FormAttachment(ysButtons[ysButtons.length - 1], 13);
			fd_txt_ys.top = new FormAttachment(lblNewLabel_6, -10, SWT.TOP);
			fd_txt_ys.bottom = new FormAttachment(lblNewLabel_6, 0, SWT.BOTTOM);
			txt_ys.setLayoutData(fd_txt_ys);

			boxBindingUtil.bindTextState(ysButtons[ysButtons.length - 1], txt_ys, true);

			Label lblNewLabel_7 = toolkit.createLabel(composite_1, "燃料：", SWT.NONE);
			FormData fd_lblNewLabel_7 = new FormData();
			fd_lblNewLabel_7.top = new FormAttachment(lblNewLabel_6, 30);
			fd_lblNewLabel_7.right = new FormAttachment(label_5, 0, SWT.RIGHT);
			lblNewLabel_7.setLayoutData(fd_lblNewLabel_7);

			Button[] rlButtons = CommonUtils.initCheckBoxUI(toolkit, composite_1, lblNewLabel_7, "RL", new int[] { 15, 10, 15, 15, 15 }, hrFamily, "fuelType");

			txt_rlqt = toolkit.createText(composite_1, "", SWT.NONE);
			FormData fd_txt_rlqt = new FormData();
			fd_txt_rlqt.right = new FormAttachment(rlButtons[rlButtons.length - 1], 120, SWT.RIGHT);
			fd_txt_rlqt.left = new FormAttachment(rlButtons[rlButtons.length - 1], 13);
			fd_txt_rlqt.top = new FormAttachment(lblNewLabel_7, -10, SWT.TOP);
			fd_txt_rlqt.bottom = new FormAttachment(lblNewLabel_7, 0, SWT.BOTTOM);
			txt_rlqt.setLayoutData(fd_txt_rlqt);

			boxBindingUtil.bindTextState(rlButtons[rlButtons.length - 1], txt_rlqt, true);

			Label lblNewLabel_10 = toolkit.createLabel(composite_1, "禽畜栏：", SWT.NONE);
			FormData fd_lblNewLabel_10 = new FormData();
			fd_lblNewLabel_10.bottom = new FormAttachment(lblNewLabel_7, 0, SWT.BOTTOM);
			fd_lblNewLabel_10.right = new FormAttachment(lblNewLabel_5, 0, SWT.RIGHT);
			lblNewLabel_10.setLayoutData(fd_lblNewLabel_10);

			combo_scl = new Combo(composite_1, SWT.NONE);
			FormData fd_combo_6 = new FormData();
			fd_combo_6.bottom = new FormAttachment(lblNewLabel_10, 0, SWT.BOTTOM);
			fd_combo_6.right = new FormAttachment(lblNewLabel_10, 136, SWT.RIGHT);
			fd_combo_6.top = new FormAttachment(lblNewLabel_10, -10, SWT.TOP);
			fd_combo_6.left = new FormAttachment(lblNewLabel_10, 10);
			combo_scl.setLayoutData(fd_combo_6);
			toolkit.adapt(combo_scl);
			toolkit.paintBordersFor(combo_scl);

			Label lblNewLabel_8 = toolkit.createLabel(composite_1, "卫生厕所：", SWT.NONE);
			FormData fd_lblNewLabel_8 = new FormData();
			fd_lblNewLabel_8.top = new FormAttachment(lblNewLabel_7, 30);
			fd_lblNewLabel_8.right = new FormAttachment(lblNewLabel_7, 0, SWT.RIGHT);
			lblNewLabel_8.setLayoutData(fd_lblNewLabel_8);

			combo_wscs = new Combo(composite_1, SWT.NONE);
			FormData fd_combo_4 = new FormData();
			fd_combo_4.bottom = new FormAttachment(lblNewLabel_8, 2, SWT.BOTTOM);
			fd_combo_4.right = new FormAttachment(lblNewLabel_8, 136, SWT.RIGHT);
			fd_combo_4.top = new FormAttachment(lblNewLabel_8, -10, SWT.TOP);
			fd_combo_4.left = new FormAttachment(lblNewLabel_8, 6);
			combo_wscs.setLayoutData(fd_combo_4);
			toolkit.adapt(combo_wscs);
			toolkit.paintBordersFor(combo_wscs);

			Label lblNewLabel_9 = toolkit.createLabel(composite_1, "非卫生厕所：", SWT.NONE);
			FormData fd_lblNewLabel_9 = new FormData();
			fd_lblNewLabel_9.bottom = new FormAttachment(lblNewLabel_8, 0, SWT.BOTTOM);
			fd_lblNewLabel_9.right = new FormAttachment(lblNewLabel_4, 0, SWT.RIGHT);
			lblNewLabel_9.setLayoutData(fd_lblNewLabel_9);

			combo_fwscs = new Combo(composite_1, SWT.NONE);
			FormData fd_combo_5 = new FormData();
			fd_combo_5.bottom = new FormAttachment(lblNewLabel_9, 0, SWT.BOTTOM);
			fd_combo_5.right = new FormAttachment(lblNewLabel_9, 136, SWT.RIGHT);
			fd_combo_5.top = new FormAttachment(lblNewLabel_9, -10, SWT.TOP);
			fd_combo_5.left = new FormAttachment(lblNewLabel_9, 10);
			combo_fwscs.setLayoutData(fd_combo_5);
			toolkit.adapt(combo_fwscs);
			toolkit.paintBordersFor(combo_fwscs);

			Label lblNewLabel_11 = toolkit.createLabel(composite_1, "垃圾处理：", SWT.NONE);
			FormData fd_lblNewLabel_11 = new FormData();
			fd_lblNewLabel_11.bottom = new FormAttachment(lblNewLabel_9, 0, SWT.BOTTOM);
			fd_lblNewLabel_11.right = new FormAttachment(lblNewLabel_10, 0, SWT.RIGHT);
			lblNewLabel_11.setLayoutData(fd_lblNewLabel_11);

			combo_ljcl = new Combo(composite_1, SWT.NONE);
			FormData fd_combo_7 = new FormData();
			fd_combo_7.bottom = new FormAttachment(lblNewLabel_11, 0, SWT.BOTTOM);
			fd_combo_7.right = new FormAttachment(lblNewLabel_11, 136, SWT.RIGHT);
			fd_combo_7.top = new FormAttachment(lblNewLabel_11, -10, SWT.TOP);
			fd_combo_7.left = new FormAttachment(lblNewLabel_11, 10);
			combo_ljcl.setLayoutData(fd_combo_7);
			toolkit.adapt(combo_ljcl);
			toolkit.paintBordersFor(combo_ljcl);

			txt_ljclqt = toolkit.createText(composite_1, "", SWT.NONE);
			FormData fd_txtNewText_9 = new FormData();
			fd_txtNewText_9.right = new FormAttachment(combo_ljcl, 120, SWT.RIGHT);
			fd_txtNewText_9.left = new FormAttachment(combo_ljcl, 13);
			fd_txtNewText_9.top = new FormAttachment(lblNewLabel_11, -10, SWT.TOP);
			fd_txtNewText_9.bottom = new FormAttachment(lblNewLabel_11, 0, SWT.BOTTOM);
			txt_ljclqt.setLayoutData(fd_txtNewText_9);

			Label lblNewLabel_13 = toolkit.createLabel(composite_1, "家用电器：", SWT.NONE);
			FormData fd_lblNewLabel_13 = new FormData();
			fd_lblNewLabel_13.top = new FormAttachment(lblNewLabel_8, 30);
			fd_lblNewLabel_13.right = new FormAttachment(lblNewLabel_8, 0, SWT.RIGHT);
			lblNewLabel_13.setLayoutData(fd_lblNewLabel_13);

			Button[] jydqButtons = CommonUtils.initCheckBoxUI(toolkit, composite_1, lblNewLabel_13, "JYDQ", new int[] { 15 }, hrFamily, "jydq");

			Label lblNewLabel_14 = toolkit.createLabel(composite_1, "交通工具：", SWT.NONE);
			FormData fd_lblNewLabel_14 = new FormData();
			fd_lblNewLabel_14.top = new FormAttachment(lblNewLabel_13, 30);
			fd_lblNewLabel_14.right = new FormAttachment(lblNewLabel_13, 0, SWT.RIGHT);
			lblNewLabel_14.setLayoutData(fd_lblNewLabel_14);

			Button[] jtgjButtons = CommonUtils.initCheckBoxUI(toolkit, composite_1, lblNewLabel_14, "JTGJ", new int[] { 15, 15, 3 }, hrFamily, "jtgu");

			for(int i = 0; i < composite.getChildren().length - 1; i++) {
				composite.getChildren()[i].addTraverseListener(ListenerUtil.traverseListener);
			}
		}

	}

	protected void doExport() {

	}

	public void doTableAdd(Control control) {
		if(control == familyMemberTable) {
			if(familyMemberTable.getDataList() == null || familyMemberTable.getDataList().size() == 0)
				doAddItem();
		}
	}

	protected abstract void doCancel();

	protected abstract void doSave();

	protected abstract void doAdd();

	protected abstract void doDel();

	protected abstract void doEdit();

	protected abstract void doExit();

	protected void doDelItem() {
		if(familyMemberTable.getSelection() == null) {
			DialogManager.invokeWarnDlg(Messages.getString("FamilyUI_INFO.10"));
			return;
		}
		List<Object> list = familyMemberTable.getDataList();
		if(list != null && list.size() > 0) {
			int size = list.size() - 1;
			HrPerson mx = (HrPerson) familyMemberTable.getSelection();
			// if(mx.getPerRelaMaster().longValue() == Constants.HZ.longValue())
			// {
			// DialogManager.invokeWarnDlg(Messages.getString("FamilyUI_INFO.11"));
			// return;
			// }
			if(hrPerson != null && mx.getId().longValue() == hrPerson.getId().longValue()) {
				DialogManager.invokeWarnDlg(Messages.getString("FamilyUI_INFO.11"));
				return;
			}
			int index = list.indexOf(mx);
			familyMemberTable.remove(mx);
			familyMemberTable.redraw();
			if(size > 0 && size == index) {
				familyMemberTable.setSelection(familyMemberTable.getDataList().size() - 1);
			}
		}
	}

	protected void doAddItem() {
		List<Object> list = familyMemberTable.getDataList();
		if(list != null && list.size() > 0) {
			HrPerson hrPerson = (HrPerson) list.get(list.size() - 1);
			if(!doCheck(hrPerson))
				return;
		}
		HrPerson hrPerson = new HrPerson();
		familyMemberTable.doAdd(hrPerson);
		familyMemberTable.setSelection(familyMemberTable.getDataList().indexOf(hrPerson), 1);
	}

	protected void doAddHuZhuToTable(HrPerson hrPerson) {
		if(!isContantsPerson(hrPerson)) {
			hrPerson.setPerRelaMaster(Constants.HZ);
			familyMemberTable.doAdd(hrPerson);
//			familyMemberTable.setSelection(familyMemberTable.getDataList().indexOf(hrPerson), 1);
			familyMemberTable.redraw();
		}
	}

	private boolean isContantsPerson(HrPerson person) {
		List<Object> list = familyMemberTable.getDataList();
		if(list != null || list.size() > 0) {
			for(int i = 0; i < list.size(); i++) {
				HrPerson temp = (HrPerson) list.get(i);
				if(temp.getId().longValue() == person.getId().longValue()) {
					return true;
				}
			}
		}
		return false;
	}

	protected void doSaveItem() {
		if(doSaveBefore()) {
			List<HrPerson> personList = new ArrayList<HrPerson>();
			HrPerson p;
			List<Object> objectList = familyMemberTable.getDataList();
			for(Object o : objectList) {
				p = (HrPerson) o;
				for(HrPerson person : personList) {
					if(person.getId().longValue() == p.getId().longValue()) {
						break;
					}
				}
				personList.add(p);
			}
			boolean b = false;
			try {
				b = DataSource.hrPersonService.updateFamilyRelation(hrFamily.getId(), personList);
				if(b) {
					DialogManager.invokeInfoDlg(Messages.getString("FamilyUI_INFO.0"));
				}
			}
			catch(Exception e) {
				DialogManager.invokeWarnDlg(Messages.getString("FamilyUI_INFO.1") + e.getMessage());
			}
		}
	}

	protected void removeEmpRow() {
		List<Object> list = familyMemberTable.getDataList();
		if(list.size() > 0) {
			HrPerson mx = (HrPerson) list.get(list.size() - 1);
			if(Assert.isNull(mx.getId())) {
				familyMemberTable.remove(mx);
				familyMemberTable.redraw();
			}
		}
	}

	protected void removeAllMember() {
		familyMemberTable.setInput(null);
	}

	/**
	 * 保存前验证
	 * 
	 * @return
	 */
	protected boolean doSaveBefore() {
		removeEmpRow();
		if(Assert.isNull(hrFamily) || hrFamily.getId() == null) {
			DialogManager.invokeInfoDlg(Messages.getString("FamilyUI_ERROR.2")); //$NON-NLS-1$
			txt_hzxm.setFocus();
			return false;
		}
		List<Object> list = familyMemberTable.getDataList();
		if(list == null || list.size() == 0) {
			DialogManager.invokeInfoDlg(Messages.getString("FamilyUI_ERROR.3")); //$NON-NLS-1$
			return false;
		}
		for(Object obj : list) {
			if(!doCheck((HrPerson) obj))
				return false;
		}
		return true;
	}

	public boolean doCheck(HrPerson person) {
		if(StringUtils.isBlank(person.getName())) {
			DialogManager.invokeWarnDlg(Messages.getString("FamilyUI_ERROR.0"));
			familyMemberTable.setSelection(getIndex(hrPerson), getDescBybh("name"));
			return false;
		}
		if(person.getPerRelaMaster() == null) {
			DialogManager.invokeWarnDlg(Messages.getString("FamilyUI_ERROR.1"));
			familyMemberTable.setSelection(getIndex(person), getDescBybh("perRelaMaster"));
			return false;
		}
		if((person.getPerRelaMaster().longValue() != Constants.HZ.longValue() && hrPerson.getId().longValue() == person.getId())) {
			DialogManager.invokeWarnDlg(Messages.getString("ValidateUI.4"));
			familyMemberTable.setSelection(getIndex(person), getDescBybh("perRelaMaster"));
			person.setPerRelaMaster(Constants.HZ);
			familyMemberTable.editElement(person, "perRelaMaster");
			return false;
		}
		if((person.getPerRelaMaster().longValue() == Constants.HZ.longValue() && hrPerson.getId().longValue() != person.getId())) {
			DialogManager.invokeWarnDlg(Messages.getString("ValidateUI.5"));
			familyMemberTable.setSelection(getIndex(person), getDescBybh("perRelaMaster"));
			return false;
		}
		return true;

	}

	protected int getIndex(HrPerson hrPerson) {
		int i = -1;
		List<Object> list = familyMemberTable.getDataList();
		if(list != null && list.size() > 0) {
			i = list.indexOf(hrPerson);
		}
		return i;

	}

	public KtableColumnDesc getKtableColumnDescByField(String field) {
		if(desclist != null && desclist.size() > 0) {
			for(int j = 0; j < desclist.size(); j++) {
				KtableColumnDesc desc = desclist.get(j);
				if(desc.getField().equals(field)) {
					return desc;
				}
			}
		}
		return null;
	}

	public int getDescBybh(String bh) {
		int i = -1;
		if(desclist != null && desclist.size() > 0) {
			for(int j = 0; j < desclist.size(); j++) {
				KtableColumnDesc desc = desclist.get(j);
				if(desc.getField().equals(bh)) {
					i = j;
					break;
				}
			}
		}
		return i;
	}

	protected void initCombo() {
		CommonUtils.initCombo(getCombo_fwlx(), "FWLX");
		CommonUtils.initCombo(getCombo_cfsyfs(), "CFSYFS");
		CommonUtils.initCombo(getCombo_cfpffs(), "CFPFSS");
		CommonUtils.initCombo(getCombo_wscs(), "WSCS");
		CommonUtils.initCombo(getCombo_fwscs(), "FWSCS");
		CommonUtils.initCombo(getCombo_scl(), "SCL");
		CommonUtils.initCombo(getCombo_ljcl(), "LJCL");
	}

	protected abstract void doPrint();

	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
	}

	protected void setActionControl() {
		if(viewstate == FamilyInfoViewState.ADD_VIEW || viewstate == FamilyInfoViewState.EDIT_VIEW) {
			toolItemAdd.setEnabled(false);
			toolItemEdit.setEnabled(false);
			toolItemDel.setEnabled(false);
			toolItemCancel.setEnabled(true);
			toolItemSave.setEnabled(true);
			if(viewstate == FamilyInfoViewState.ADD_VIEW) {
				changeState(true, 0);
			} else {
				changeState(true, 1);
			}
			toolFamilyItemAdd.setEnabled(true);
			toolFamilyItemDel.setEnabled(true);
			toolFamilyItemEdit.setEnabled(true);

		} else if(viewstate == FamilyInfoViewState.SHOW_VIEW) {

			toolItemAdd.setEnabled(true);
			toolItemEdit.setEnabled(true);
			toolItemDel.setEnabled(true);
			toolItemCancel.setEnabled(false);
			toolItemSave.setEnabled(false);

			toolFamilyItemAdd.setEnabled(false);
			toolFamilyItemDel.setEnabled(false);
			toolFamilyItemEdit.setEnabled(false);

			changeState(false, 1);
		}

	}

	protected void changeState(boolean showFlag, int type) {
		switch (type) {
			case 0:
				getTxt_hzxm().setEnabled(showFlag);
				chooseHuZuLink.setEnabled(showFlag);
				text_dabh.setEnabled(showFlag);
				generNolink.setEnabled(showFlag);
				break;
			case 1:
				text_dabh.setEnabled(showFlag);
				generNolink.setEnabled(showFlag);
				getTxt_hzxm().setEnabled(showFlag);
				chooseHuZuLink.setEnabled(!showFlag);
				break;
			case 2:
				getTxt_hzxm().setEnabled(showFlag);
				chooseHuZuLink.setEnabled(showFlag);
				break;
		}

	}

	public Combo getCombo_fwlx() {
		return combo_fwlx;
	}

	public Combo getCombo_cfsyfs() {
		return combo_cfsyfs;
	}

	public Combo getCombo_cfpffs() {
		return combo_cfpffs;
	}

	public Combo getCombo_wscs() {
		return combo_wscs;
	}

	public Combo getCombo_fwscs() {
		return combo_fwscs;
	}

	public Combo getCombo_scl() {
		return combo_scl;
	}

	public Combo getCombo_ljcl() {
		return combo_ljcl;
	}

	public Text getTxt_fwlx() {
		return txt_fwlx;
	}

	public Text getTxt_ljclqt() {
		return txt_ljclqt;
	}

	public GeographyTreeCombo getCombo_jwh() {
		return combo_jwh;
	}

	public Text getTxt_hzxm() {
		return txt_hzxm;
	}

}
